Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correction to M-test with resampling, and addition of new MLL test #268

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Serra314
Copy link

@Serra314 Serra314 commented Oct 15, 2024

pyCSEP Pull Request Checklist

Please check out the contributing guidelines for some tips
on making pull requests to pyCSEP.

Fixes issue #(please fill in or delete if not needed).

Type of change:

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Unpublished science feature (This may require a science review)
  • This change requires a documentation update

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@pabloitu pabloitu self-assigned this Oct 15, 2024
@pabloitu pabloitu marked this pull request as draft October 15, 2024 15:41
@pabloitu pabloitu added the enhancement New feature or request label Oct 15, 2024
…ampling from the entire stochastic set is possible now with the full_calculation flag. Removed mag_half_bin, which is now calculated directly from the region magnitude bins.
@pabloitu pabloitu marked this pull request as ready for review October 21, 2024 20:10
…nitude_test and MLL_score.

docs: updated URLs for intersphinx. Added new M-tests to the API reference.
Copy link
Collaborator

@pabloitu pabloitu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functions are looking great!!

Unit tests were created for simple catalog/forecasts. The function results were reproduced by hand calculation, or my third-person implementation of the scores from just reading the manuscript.

California Landers forecast and catalog (pycsep) were tested with the function, and provided same result as given by author. Didn't placed this in the unit-testing suite, since its too costly. Should be placed into QA tests with the other tests in the future.

Only pendings are to write a docstring of log_d_multinomial (@Serra314), confirm that it is a +2 and not -2 in the return value of the MLL_score (@Serra314) and write a documentation snippet in the documentation: (1) Getting Started / Theory of CSEP Tests and (2) Concepts /Evaluations.



def log_d_multinomial(x: numpy.ndarray, size: int, prob: numpy.ndarray):
"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires docstrings explaining how it was calculated and/or derived from the MS.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the multinomial log-likelihood which is given by

log( Γ(size + 1) ) + Σ_i x_i log(prob_i ) - log( Γ(x_i + 1) )

N_j = numpy.sum(catalog_counts)
events_ratio = N_u / N_j

union_catalog_counts_mod = union_catalog_counts + events_ratio
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the named Lambda_U and Lambda_j to this more python variable names (No start with caps). Let me know if u agree :D or have other suggestion.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is okay for me

size=numpy.sum(catalog_counts_mod),
prob=pr_cat_j)

return 2 * (log_lik_merged - log_lik_union - log_like_cat_j)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a negative -2?? Or did we flip the score? I'm always confused when flipping.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it should according to the definition in the manuscript. I'll change that. The minus sign does not change any property of the MLL statistic and it just make it positively or negatively oriented, so no issue changing the definition.

@pabloitu pabloitu mentioned this pull request Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants